package com.linkit.main;

import android.content.Context;
import android.os.Handler;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

/**
 * Hiệu ứng animation cho ứng dụng
 * 
 * @author DvHien
 */
public class GeneralAnimationUtils {
	private static Context context = MainActivity.getInstance();
	/** Hiệu ứng chuyển tab trái sang phải */
	public static void startLeftToRight(View viewHide, View viewShow) {
		
		Animation animLeftToRightShow = AnimationUtils.loadAnimation(context,
				R.anim.anim_left_to_right_show);
		Animation animRightToLeftHide = AnimationUtils.loadAnimation(context,
				R.anim.anim_right_to_left_hide);
		viewHide.startAnimation(animRightToLeftHide);
		viewShow.startAnimation(animLeftToRightShow);

	}
	
	/** Hiệu ứng chuyển tab trái sang phải và thực hiện callback */
	public static void startLeftToRight(View viewHide, View viewShow, final FinishedCallback callback) {
		Animation animLeftToRightShow = AnimationUtils.loadAnimation(context,
				R.anim.anim_left_to_right_show);
		Animation animRightToLeftHide = AnimationUtils.loadAnimation(context,
				R.anim.anim_right_to_left_hide);
		viewHide.startAnimation(animRightToLeftHide);
		viewShow.startAnimation(animLeftToRightShow);
		
		new Handler().postDelayed(new Runnable() {

			@Override
			public void run() {
				callback.finish();
			}
		}, animLeftToRightShow.getDuration());

	}

	/** Hiệu ứng chuyển tab phải sang trái */
	public static void startRightToLeft(final View viewHide, View viewShow) {
		final Animation animRightToLeftShow = AnimationUtils.loadAnimation(
				context, R.anim.anim_right_to_left_show);
		Animation animLeftToRightHide = AnimationUtils.loadAnimation(context,
				R.anim.anim_left_to_right_hide);
		viewHide.startAnimation(animLeftToRightHide);
		viewShow.startAnimation(animRightToLeftShow);
	}
	
	/** Hiệu ứng chuyển tab phải sang trái */
	public static void startRightToLeft(final View viewHide, View viewShow, final FinishedCallback callback) {
		final Animation animRightToLeftShow = AnimationUtils.loadAnimation(
				context, R.anim.anim_right_to_left_show);
		Animation animLeftToRightHide = AnimationUtils.loadAnimation(context,
				R.anim.anim_left_to_right_hide);
		viewHide.startAnimation(animLeftToRightHide);
		viewShow.startAnimation(animRightToLeftShow);
		
		new Handler().postDelayed(new Runnable() {

			@Override
			public void run() {
				callback.finish();
			}
		}, animRightToLeftShow.getDuration());
	}

	/** Hiệu ứng ẩn từ dưới lên trên */
	public static void startBottomToTop(View viewHide, final FinishedCallback anim) {
		Animation animBottomToTopHide = AnimationUtils.loadAnimation(context,
				R.anim.anim_bottom_to_top_show);
		viewHide.startAnimation(animBottomToTopHide);
		new Handler().postDelayed(new Runnable() {

			@Override
			public void run() {
				anim.finish();
			}
		}, animBottomToTopHide.getDuration());

	}

	/** Hiệu ứng hiển thị từ trên xuống dưới */
	public static void startTopToBottom(View viewShow, final FinishedCallback anim) {
		Animation animTopToBottomShow = AnimationUtils.loadAnimation(context,
				R.anim.anim_top_to_bottom_hide);
		viewShow.startAnimation(animTopToBottomShow);
		new Handler().postDelayed(new Runnable() {

			@Override
			public void run() {
				anim.finish();
			}
		}, animTopToBottomShow.getDuration());
	}
	
	/** Hiệu ứng hiển thị từ trên xuống dưới */
	public static void startTopToBottom(View viewShow) {
		Animation animTopToBottomShow = AnimationUtils.loadAnimation(context,
				R.anim.anim_top_to_bottom_hide);
		viewShow.startAnimation(animTopToBottomShow);
	}
	
	/** Hiệu ứng hiển thị từ dưới lên trên */
	public static void startBottomToTop(View viewShow) {
		Animation animTopToBottomShow = AnimationUtils.loadAnimation(context,
				R.anim.anim_bottom_to_top_show);
		viewShow.startAnimation(animTopToBottomShow);
	}

	/** Hiệu ứng hiển thị dialog rõ dần */
	public static void startShowDialog(View viewShow) {
		Animation animShowDialog = AnimationUtils.loadAnimation(context,
				R.anim.anim_dialog_show);
		viewShow.startAnimation(animShowDialog);
	}

	/** Hiệu ứng ẩn dialog mờ dần */
	public static void startHideDialog(View viewHide, final FinishedCallback callback) {
		Animation animHideDialog = AnimationUtils.loadAnimation(context,
				R.anim.anim_dialog_hide);
		viewHide.startAnimation(animHideDialog);
		new Handler().postDelayed(new Runnable() {
			@Override
			public void run() {

				callback.finish();
			}
		}, animHideDialog.getDuration());
	}
}
